package com.jokerpan.project.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jokerpan.project.commons.ActionResult;
import com.jokerpan.project.commons.PaginationBuilder;
import com.jokerpan.project.commons.ResultBuilder;
import com.jokerpan.project.entity.SysLogs;
import com.jokerpan.project.mapper.SysLogsMapper;
import com.jokerpan.project.service.SysLogsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author jokerpan
 */
@Service("sysLogsService")
public class SysLogsServiceImpl implements SysLogsService {

    @Resource
    SysLogsMapper sysLogsMapper;


    @Override
    public Map<String, Object> queryList(SysLogs sysLogs) {
        Page<Object> page = PageHelper.startPage(sysLogs.getCurrentPage(), sysLogs.getPageSize());
        List<SysLogs> resultList = this.sysLogsMapper.queryList(sysLogs);
        return PaginationBuilder.buildResult(resultList, page.getTotal(), sysLogs.getCurrentPage(), sysLogs.getPageSize());
    }

    @Override
    public Boolean add(SysLogs sysLogs) {
        return this.sysLogsMapper.add(sysLogs) > 0;
    }

    @Override
    public ActionResult update(SysLogs sysLogs) {
        if(this.sysLogsMapper.update(sysLogs) > 0){
            return ResultBuilder.buildActionSuccess();
        }else {
            return ResultBuilder.buildActionFailed();
        }
    }

    @Override
    public ActionResult deleteById(Integer id) {
        if(this.sysLogsMapper.deleteById(id) > 0){
            return ResultBuilder.buildActionSuccess();
        }else {
            return ResultBuilder.buildActionFailed();
        }
    }
}
